<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>垂直居中布局解决方案2-绝对定位position</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #parent {
      width: 500px;
      height: 500px;
      background-color: red;
      position: relative;
    }

    #child {
      position: absolute;
      /* top:50%;
      left:50%;
      margin-top:-100px;
      margin-left:-100px; */

      /* transform:translate(-50%,-50%); */

      top:0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
      width: 200px;
      height: 200px;
      background-color: green;
    }
  </style>
</head>

<body>
  <!-- 定义父级元素 -->
  <div id="parent">
    <!-- 定义子级元素 -->
    <div id="child"></div>
  </div>
</body>

</html>